import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

/**
 * @author Jiange
 * @create 2021-08-10-22:48
 */
public class TCPTest {

    public static void client() throws IOException {
        InetAddress inetAddress = InetAddress.getByName("localhost");
        Socket socket = new Socket(inetAddress.getHostName(),8899);
        OutputStream outputStream = socket.getOutputStream();
        Scanner scanner = new Scanner(System.in);

        while (true){
            String next = scanner.next();
            outputStream.write(next.getBytes());

            socket.shutdownOutput();

            InputStream inputStream = socket.getInputStream();
            byte[] bytes = inputStream.readAllBytes();
            if(new String(bytes).equals("88")){
                System.exit(0);
            }
            System.out.println(new String(bytes));
        }
    }

    public static void main(String[] args) throws IOException {
        client();
    }
}
